﻿using System.Reflection;
using System;




namespace HW_d3
{
    class Program
    {
        static void Main(string[] args)
        {
            // 获取 Person 类型
            Type personType = typeof(Person);

            // 获取无参数构造方法并创建实例
            ConstructorInfo defaultConstructor = personType.GetConstructor(Type.EmptyTypes);
            object person1 = defaultConstructor.Invoke(null);
            Console.WriteLine(person1);

            // 获取有参数构造方法并创建实例
            ConstructorInfo parameterizedConstructor = personType.GetConstructor(new Type[] { typeof(string), typeof(int) });
            object person2 = parameterizedConstructor.Invoke(new object[] { "Alice", 30 });
            Console.WriteLine(person2);
        }
    }

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }

        public Person() { }

        public Person(string name, int age)
        {
            Name = name;
            Age = age;
        }

        public override string ToString()
        {
            return $"Name: {Name}, Age: {Age}";
        }
    }
}
